.TH std::piecewise_construct,std::piecewise_construct_t 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::piecewise_construct,std::piecewise_construct_t \- std::piecewise_construct,std::piecewise_construct_t

.SH Synopsis
   Defined in header <utility>
   struct piecewise_construct_t { explicit              \fB(1)\fP \fI(since C++11)\fP
   piecewise_construct_t() = default; };
   constexpr std::piecewise_construct_t                                   \fI(since C++11)\fP
   piecewise_construct{};                               \fB(2)\fP               \fI(until C++17)\fP
   inline constexpr std::piecewise_construct_t                            \fI(since C++17)\fP
   piecewise_construct{};

   1) std::piecewise_construct_t is an empty class tag type used to disambiguate
   between different functions that take two tuple arguments.
   2) The constant std::piecewise_construct is an instance of \fB(1)\fP.

   The overloads that do not use std::piecewise_construct_t assume that each tuple
   argument becomes the element of a pair. The overloads that use
   std::piecewise_construct_t assume that each tuple argument is used to construct,
   piecewise, a new object of specified type, which will become the element of the
   pair.

.SH Example



// Run this code

 #include <iostream>
 #include <tuple>
 #include <utility>

 struct Foo
 {
     Foo(std::tuple<int, float>)
     {
         std::cout << "Constructed a Foo from a tuple\\n";
     }

     Foo(int, float)
     {
         std::cout << "Constructed a Foo from an int and a float\\n";
     }
 };

 int main()
 {
     std::tuple<int, float> t(1, 3.14);

     std::cout << "Creating p1...\\n";
     std::pair<Foo, Foo> p1(t, t);

     std::cout << "Creating p2...\\n";
     std::pair<Foo, Foo> p2(std::piecewise_construct, t, t);
 }

.SH Output:

 Creating p1...
 Constructed a Foo from a tuple
 Constructed a Foo from a tuple
 Creating p2...
 Constructed a Foo from an int and a float
 Constructed a Foo from an int and a float

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to              Behavior as published              Correct behavior
   LWG 2510 C++11      the default constructor was non-explicit, which made explicit
                       could lead to ambiguity

.SH See also

   constructor   constructs new pair
                 \fI(public member function of std::pair<T1,T2>)\fP
